package cn.hl.hm.util.chinapay;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

/**
 * 系统锟斤拷锟斤拷锟斤拷锟斤拷.
 */
public class Constant {
	/**
	 * 锟斤拷志.
	 */
	private static Logger logger = Logger.getLogger(Constant.class);
	/**
	 * 系统锟斤拷锟斤拷.
	 */
	public static final String CHAR_SET = "UTF-8";
	
	public static final Double discountNum = 1d;
	/**
	 * HTML CONTENT_TYPE.
	 */
	public static final String HTML_CONTENT_TYPE = "text/html; charset=UTF-8";
	/**
	 * 锟斤拷锟斤拷锟街段分革拷锟斤拷.
	 */
	public static final String DATA_SPLIT_STR = "|";
	/**
	 * 锟斤拷锟斤拷锟斤拷式锟街段分革拷锟斤拷.
	 */
	public static final String REGEX_DATA_SPLIT_STR = "[|]";
	/**
	 * 应锟斤拷锟斤拷锟斤拷锟�
	 */
	public static final String PARAM_RESP_CODE = "respCode";
	/**
	 * 应锟斤拷锟斤拷息锟斤拷锟斤拷.
	 */
	public static final String PARAM_RESP_MSG = "respMsg";
	/**
	 * 锟斤拷锟斤拷锟侥硷拷.
	 */
	public static final String DEFAULT_BUNDLE_NAME = "demo";
	/**
	 * CLASS路锟斤拷.
	 */
	public static final String CLASS_PATH;
	/**
	 * numberChar.
	 */
	public static final String numberChar = "0123456789";
	/**
	 * 锟斤拷锟斤拷司锟教伙拷锟斤拷:15位锟斤拷锟斤拷.
	 */
	public static final String PARAM_MER_ID = "200402090000001";
	/**
	 * 锟斤拷锟斤拷锟斤拷锟斤拷:锟斤拷锟斤拷.
	 */
	public static final String PARAM_TRANS_TYPE_OPEN = "1010";
	/**
	 * 锟斤拷锟斤拷锟斤拷锟斤拷:锟疥购.
	 */
	public static final String PARAM_TRANS_TYPE_BUY = "3010";
	/**
	 * 锟矫伙拷锟斤拷锟斤拷:CD锟斤拷锟竭硷拷锟矫伙拷.
	 */
	public static final String PARAM_USER_TYPE_ADV = "8";
	/**
	 * 锟矫伙拷锟斤拷锟斤拷:锟斤拷通锟矫伙拷.
	 */
	public static final String PARAM_USER_TYPE_NOR = "9";
	/**
	 * 锟矫伙拷锟斤拷锟斤拷:锟斤拷业锟酵伙拷.
	 */
	public static final String PARAM_USER_TYPE_ENT = "0";

	/**
	 * 锟皆憋拷:女.
	 */
	public static final String PARAM_GENDER_FEMALE = "F";
	/**
	 * 锟皆憋拷:锟斤拷.
	 */
	public static final String PARAM_GENDER_MALE = "M";
	
	/**
	 * 锟斤拷锟杰斤拷锟斤拷时锟芥储支锟斤拷锟斤拷锟斤拷锟斤拷息.
	 */
	public static Map<String, String> noPwdMap = new HashMap<String, String>(); 
	
	static {
		String classpath = Constant.class.getResource("/log4j.properties").getPath();
		File f = new File(classpath);
		CLASS_PATH = f.getParent() + File.separator;
	}

	/**
	 * 锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷取锟斤拷锟斤拷锟斤拷息.
	 * 
	 * @param key
	 *            锟斤拷锟斤拷锟斤拷
	 * @return 锟斤拷锟斤拷值
	 */
	public static String getString(String key) {
		return getString(DEFAULT_BUNDLE_NAME, key);
	}

	/**
	 * 锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷取锟斤拷锟斤拷锟斤拷息.
	 * 
	 * @param bundleName
	 *            bundleName
	 * @param key
	 *            锟斤拷锟斤拷锟斤拷
	 * @return 锟斤拷锟斤拷值
	 */
	public static String getString(String bundleName, String key) {
		try {
			ResourceBundle bundle = ResourceBundle.getBundle(bundleName);
			return bundle.getString(key);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return "";
	}
	

	/**
	 * 锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟斤拷锟�只锟斤拷锟斤拷锟斤拷小写锟斤拷母锟斤拷锟斤拷锟斤拷).
	 * 
	 * @param length
	 *            锟斤拷锟斤拷址锟斤拷锟斤拷锟斤拷锟�
	 * @return String
	 */
	public static String generateString(int length) {
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			sb.append(numberChar.charAt(random.nextInt(numberChar.length())));
		}
		return sb.toString();
	}
	
	/**
	 * 锟斤拷锟斤拷锟街凤拷锟斤拷.
	 * 
	 * @param str
	 *            锟街凤拷锟斤拷
	 * @return String
	 */
	public static String trimStr(String str) {
		
		return  str == null ? "":str.toString();
	}
}
